//
//  UIView+Extension.m
//  黑马微博2期
//
//  Created by apple on 14-10-7.
//  Copyright (c) 2014年 heima. All rights reserved.
//

#import "UIView+Extension.h"

@implementation UIView (Extension)

- (void)setX:(CGFloat)x
{
    CGRect frame = self.frame;
    frame.origin.x = x;
    self.frame = frame;
}

- (void)setY:(CGFloat)y
{
    CGRect frame = self.frame;
    frame.origin.y = y;
    self.frame = frame;
}

- (CGFloat)x
{
    return self.frame.origin.x;
}

- (CGFloat)y
{
    return self.frame.origin.y;
}

- (CGFloat)rightX
{
    return self.frame.origin.x+self.frame.size.width;
}

- (CGFloat)bottomY
{
    return self.frame.origin.y+self.frame.size.height;
}

- (void)setWidth:(CGFloat)width
{
    CGRect frame = self.frame;
    frame.size.width = width;
    self.frame = frame;
}

- (void)setHeight:(CGFloat)height
{
    CGRect frame = self.frame;
    frame.size.height = height;
    self.frame = frame;
}

- (CGFloat)height
{
    return self.frame.size.height;
}

- (CGFloat)width
{
    return self.frame.size.width;
}

- (void)setSize:(CGSize)size
{
    CGRect frame = self.frame;
    frame.size = size;
    self.frame = frame;
}

- (CGSize)size
{
    return self.frame.size;
}

- (void)setOrigin:(CGPoint)origin
{
    CGRect frame = self.frame;
    frame.origin = origin;
    self.frame = frame;
}

- (CGPoint)origin
{
    return self.frame.origin;
}

- (void)setCenterX:(CGFloat)centerX
{
    CGPoint center = self.center;
    center.x = centerX;
    self.center = center;
}

- (void)setCenterY:(CGFloat)centerY
{
    CGPoint center = self.center;
    center.y = centerY;
    self.center = center;
}

- (CGFloat)centerX
{
    return self.center.x;
}

- (CGFloat)centerY
{
    return self.center.y;
}

- (void)setShadowWithColor:(UIColor *)color
{
    CGRect tempRect = self.bounds;
    UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:tempRect];
    //阴影颜色
    self.layer.shadowColor = color.CGColor;
    self.layer.masksToBounds = NO;
    ////shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
    self.layer.shadowOffset = CGSizeMake(1, 1);
    //阴影透明度
    self.layer.shadowOpacity = 0.6f;
    self.layer.shadowPath = shadowPath.CGPath;
    self.layer.shadowRadius = 4;
    //要重新设置一下颜色，不然背景会变黑色
    [self setBackgroundColor:[UIColor whiteColor]];
}


//- (BOOL)isShowingOnKeyWindow
//{
//    // 主窗口
//    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
//    
//    // 以主窗口左上角为坐标原点, 计算self的矩形框
//    CGRect newFrame = [keyWindow convertRect:self.frame fromView:self.superview];
//    CGRect winBounds = keyWindow.bounds;
//    
//    // 主窗口的bounds 和 self的矩形框 是否有重叠
//    BOOL intersects = CGRectIntersectsRect(newFrame, winBounds);
//    return !self.isHidden && self.alpha > 0.01 && self.window == keyWindow && intersects;
//}


@end
